<template>
  <div class="permission">
    <div class="desc">
      <div>
        <ep-title :title="moduleTitle"></ep-title>
        <ep-title :title="desc" style="margin-left: 15px;font-size: 16px;"></ep-title>
      </div>
    </div>
    <div class="condition">
      <div>
        <div style="flex: 0 0 auto">
          <ep-search
            v-model="b0102"
            :size="size"
            placeholder="输入点位名称搜索"
            enter-button="搜索"
            @search="onSearch"
          ></ep-search>
        </div>
        <ep-button
            :size="size"
          style="margin-left: 15px"
          icon="refresh.svg"
          @click="refresh"
        ></ep-button>
        <a-tree-select
            :size="size"
          placeholder="请选择管理区域(可多选)"
          ref="taskArea"
          allowClear
          tree-checkable
          style="margin-left: 15px; width: 18vw"
          v-model="queryParam.manageAreas"
          :show-checked-strategy="SHOW_PARENT"
          :treeData="taskAreaTree"
          @change="manageAreaChange()"
        />
        <ep-button
            style="margin-left: 10px"
            :size="size"
            @click="
            () => {
              this.allotPersonBatch();
            }
          ">批量分配人员
        </ep-button>
        <column-manage
          :column.sync="columns"
          @change="columnChange"
        ></column-manage>
        <ep-button :size="size" style="margin-left: 15px" icon="fast.svg" @click="goPage">空间地图</ep-button>
        <ep-button
            style="margin-left: 10px"
            :size="size"
            @click="
            () => {
              this.openMaterialModal();
            }
          ">媒体搜索
        </ep-button>
      </div>
      <div>
        <ep-button :size="size" style="margin-left: 15px" icon="add.svg" @click="openAdd"
          >新增</ep-button
        >
        <ep-button
            :size="size"
          style="margin-left: 15px"
          icon="export.svg"
          @click="exportFile"
          >导出</ep-button
        >
      </div>
    </div>
    <div class="ep-table">
      <vxe-table
        border="none"
        stripe
        ref="xTable"
        align="center"
        :height="tableHeight"
        :data="tableData"
        :loading="loading"
        @checkbox-all="selectAllEvent"
        @checkbox-change="selectChangeEvent"
        :filter-config="{ remote: true }"
        @filter-change="filterChange"
        :sort-config="{ remote: true, multiple: true }"
        @sort-change="sortChange"
      >
        <vxe-column type="checkbox" width="60"></vxe-column>
        <vxe-column type="seq" title="序号" width="60"></vxe-column>
        <vxe-column field="b0102" title="点位名称" width="100"></vxe-column>
        <vxe-column field="b0103" title="文物编号" width="90"></vxe-column>
        <vxe-column
          field="b0104Name"
          title="古系列类别"
          width="140"
          :filterMultiple="true"
          :filters="[]"
        ></vxe-column>
        <vxe-column
          field="b0105Name"
          title="文保等级"
          sortable
          width="180"
          :filterMultiple="true"
          :filters="[]"
        ></vxe-column>
        <vxe-column
            field="b0130"
            title="批次"
            width="100"
        ></vxe-column>
        <vxe-column
            field="fxhf"
            title="风险划分"
            width="100"
        ></vxe-column>
        <vxe-column
          field="b0106Name"
          title="时代"
          sortable
          width="120"
          :filterMultiple="true"
          :filters="[]"
        ></vxe-column>
        <vxe-column
            field="xhzq"
            title="巡护周期"
            width="100"
        ></vxe-column>
        <vxe-column
            field="b0131"
            title="检查要点"
            width="100"
        ></vxe-column>
        <vxe-column
            field="b0132Name"
            title="是否开启详情"
            width="120"
        ></vxe-column>
        <vxe-column
          field="manageArea"
          title="管理区域"
          width="200"
          :filters="[{ data: '' }]"
        >
          <template #filter="{ $panel, column }">
            <input type="type" v-for="(option, index) in column.filters" :key="index" v-model="option.data" @input="$panel.changeOption($event, !!option.data, option)">
          </template>
        </vxe-column>
        <vxe-column
            field="maintPerson"
            title="维护人员"
            width="200"
        ></vxe-column>
        <vxe-column
          field="b0109"
          title="地址"
          width="150"
          show-overflow
        ></vxe-column>
        <vxe-column
          field="b0113Name"
          title="是否核销"
          :filters="[
            { label: '是', value: '1' },
            { label: '否', value: '0' },
          ]"
          :filterMultiple="true"
          width="110"
        ></vxe-column>
        <vxe-column
          field="b0114Name"
          title="是否安全"
          :filters="[
            { label: '是', value: '1' },
            { label: '否', value: '0' },
          ]"
          :filterMultiple="true"
          width="110"
        ></vxe-column>
        <vxe-column
          field="b0115Name"
          title="是否划定保护双线"
          width="180"
          :filters="[
            { label: '是', value: '1' },
            { label: '否', value: '0' },
          ]"
          :filterMultiple="true"
        ></vxe-column>
        <vxe-column
          field="b0117Name"
          title="省级文保类别"
          width="140"
          :filterMultiple="true"
          :filters="[]"
        ></vxe-column>
        <vxe-column
          field="b0118Name"
          title="省级文保子类"
          width="140"
          :filterMultiple="true"
          :filters="[]"
        ></vxe-column>
        <vxe-column
          field="b0121"
          title="开放时间"
          sortable
          width="150"
        ></vxe-column>
        <vxe-column field="b03Info" title="监控设备" width="150"></vxe-column>
        <vxe-column
          field="updateFullName"
          title="修改人"
          width="100"
        ></vxe-column>
        <vxe-column
          field="updateTime"
          title="修改时间"
          width="110"
        ></vxe-column>
        <vxe-column
            field="dutyLeader"
            title="责任领导"
            width="110"
            :filters="[{ data: '' }]"
        >
          <template #filter="{ $panel, column }">
            <input type="type" v-for="(option, index) in column.filters" :key="index" v-model="option.data" @input="$panel.changeOption($event, !!option.data, option)">
          </template>
        </vxe-column>
        <vxe-column
            field="departmentLeader"
            title="科室领导"
            width="110"
            :filters="[{ data: '' }]"
        >
          <template #filter="{ $panel, column }">
            <input type="type" v-for="(option, index) in column.filters" :key="index" v-model="option.data" @input="$panel.changeOption($event, !!option.data, option)">
          </template>
        </vxe-column>
        <vxe-column field="operate" title="操作" width="250" fixed="right">
          <template slot-scope="scope">
            <ep-button
              size="small"
              type="rank"
              @click="operate(scope.row, 'query')"
              >查看</ep-button
            >
            <ep-button
              size="small"
              type="rank"
              style="margin-left: 8px"
              @click="operate(scope.row, 'edit')"
              >编辑</ep-button
            >
            <ep-button
                size="small"
                type="rank"
                style="margin-left: 8px"
                @click="allotOnePerson(scope.row)"
            >分配人员</ep-button
            >
          </template>
        </vxe-column>
      </vxe-table>
      <vxe-pager
        :layouts="[
          'Sizes',
          'PrevJump',
          'PrevPage',
          'Number',
          'NextPage',
          'NextJump',
          'FullJump',
          'PageCount',
          'Total',
        ]"
        :current-page.sync="pageInfo.currentPage"
        :page-size.sync="pageInfo.pageSize"
        :total="pageInfo.total"
        :page-sizes="[200, 500, 1000, 5000, 10000]"
        @page-change="handlePageChange"
      >
        <template #left>
						<span class="page-left">
							<span style="padding-left: 10px"
              >已选中 {{ count }} 条</span
              >
						</span>
        </template>
      </vxe-pager>
    </div>
    <a-modal
      :title="modalTitle"
      centered
      style="top: 20px"
      width="80%"
      destroyOnClose
      v-model="visible"
      cancelText="关闭"
      okText="保存"
      @ok="handleForm"
      :ok-button-props="{ props: { disabled: okButtonDisabled } }"
    >
      <pointInfo
        ref="pointInfo"
        :b0101="objectInfo.b0101"
        :saveFlag="saveFlag"
        :c0303="queryParam.c0303"
        :flag="flag"
        :classify="'4'"
      />
    </a-modal>

    <a-modal
      title="分配维护人员"
      centered
      style="top: 20px"
      width="65%"
      destroyOnClose
      v-model="formVisible"
      cancelText="关闭"
      okText="保存"
      @ok="handleOk"
      @cancel="handleCancel">
      <maint-person-form :list-query="findGJResource"  @handleCancel="handleCancel" ref="maintPersonForm"/>
    </a-modal>

    <a-modal
        title="材料搜索"
        centered
        style="top: 20px"
        width="65%"
        v-model="materialVisible"
        cancelText="关闭"
        okText="查询"
        :mask-closable="false"
        @ok="selectByMaterial"
        @cancel="()=>{this.materialVisible = false}">
      <div>
        <zh-form ref="materialFormInfo" :model="materialFormInfo"  labelAlign="right" >
          <zh-card style="width:100%;float:left">
            <zh-row :span="18">
              <zh-input
                  type="select"
                  :options="dictData.B0202"
                  :defaultFields="{ label: 'dictValue', value: 'dictKey' }"
                  label="媒体类型"
                  v-model="materialFormInfo.b0202"
              ></zh-input>
            </zh-row>
            <zh-row :span="18">
              <zh-input
                  type="text"
                  label="媒体名称"
                  v-model="materialFormInfo.b0203"
              ></zh-input>
            </zh-row>
            <div style="height: 50px">
            </div>
          </zh-card>
        </zh-form>
      </div>
    </a-modal>
  </div>
</template>

<script>
import { getBatchDict, getDictCondition } from "@/services/system/api";
import {
  getResourceObjectList,
  getSQAndJD,
  saveResource,
  updateResource,
  deleteResourceList,
  getPermissionParams,
  getResourceAllocationtheInfo
} from "@/services/system/whdngxlApi";
import pointInfo from "@/pages/whdngxl/pointInfo";
import modal from "ant-design-vue/lib/modal";
import ColumnManage from "@/components/assembly/columnManage";
import maintPersonForm from "@/pages/whdn/resourcesManager/form/maintPersonForm"
import { TreeSelect } from "ant-design-vue";
import {mapGetters} from "vuex";
import commonExcelExport from "@/excel/commExcel";
const SHOW_PARENT = TreeSelect.SHOW_PARENT;
export default {
  name: "resourcesManager",
  computed: {
    ...mapGetters(['size','userInfo']),
    b0102: {
      get() {
        return this.queryParam.b0102;
      },
      set(val) {
        this.queryParam.b0102 = val;
      },
    },
  },
  components: { ColumnManage, pointInfo,maintPersonForm },
  data() {
    return {
      okButtonDisabled: false,
      fieldVisible: false,
      columns: [],
      tableData: [],
      tableHeight: 0,
      checkRecords: [],
      loading: false,
      pageInfo: {
        total: null,
        currentPage: 1,
        pageSize: 200,
      },
      //数据字典
      dictData: {
        B0105: [],
        B0106: [],
        B0113: [],
        B0114: [],
        C0105: [],
      },
      //标题
      moduleTitle: "",
      //查询表单
      queryParam: {
        b0102: null,
        c0303: null,
        filterVOList: [],
        orderVOList: [],
        manageAreas: undefined,
      },
      taskAreaTree: [],
      SHOW_PARENT,
      selectRuleBuild: {},
      orderRuleBuild: {},
      //查询规则
      selectRule: {
        manageArea: {
          data: null,
          values: [],
          fuzzyQuery: true,
          multiple: false,
          targetField: "manageArea",
        },
        c0303: {
          data: null,
          values: [],
          fuzzyQuery: false,
          multiple: false,
          targetField: "c0303",
        },
        b0102: {
          data: null,
          values: [],
          fuzzyQuery: true,
          multiple: false,
          targetField: "b0102",
        },
        b0104Name: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0104",
        },
        b0105Name: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0105",
        },
        b0106Name: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0106",
        },
        c0105: {
          data: null,
          values: [],
          multiple: true,
          targetField: "c0105",
        },
        b0113: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0113",
        },
        b0114: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0114",
        },
        b0107: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0122",
        },
        b0108: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0123",
        },
        b0113Name: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0113",
        },
        b0114Name: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0114",
        },
        b0117Name: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0117",
        },
        b0118Name: {
          data: null,
          values: [],
          multiple: true,
          targetField: "b0118",
        },
        dutyLeader: {
          data: null,
          values: [],
          fuzzyQuery: true,
          multiple: false,
          targetField: "dutyLeader",
        },
        departmentLeader: {
          data: null,
          values: [],
          fuzzyQuery: true,
          multiple: false,
          targetField: "departmentLeader",
        },
      },
      //排序规则
      orderRule: {
        b0105Name: {
          targetField: "b0105",
          order: null,
        },
        b0106Name: {
          targetField: "b0106",
          order: null,
        },
        b0121: {
          targetField: "b0121",
          order: null,
        },
      },
      //弹出框相关参数
      modalTitle: null,
      visible: false,
      b0101: null,
      saveFlag: false,
      //选中对象
      objectInfo: {
        b0101: null,
        c0101: null,
      },
      sqData: [], //市区数据
      jdData: [], //街道数据
      jdDataBuild: [],
      b0117DictData: [],
      b0118DictData: [],
      b0118DictDataBuild: [],
      count: 0,
      formVisible: false,
      row: null,
      desc: '',
      materialVisible: false,
      materialFormInfo: {
        b0202: '',
        b0203: ''
      },
      flag: undefined
    };
  },
  created() {
    this.moduleTitle = this.$route.meta.title;
    if (this.$router.currentRoute.name === "URResourcesManager") {
      //不可移动文物
      // this.moduleTitle = '不可移动文物'
      this.queryParam.c0303 = "1";
    } else if (this.$router.currentRoute.name === "TreeResourcesManager") {
      //古树古木
      // this.moduleTitle = '古树古木'
      this.queryParam.c0303 = "2";
    } else if (this.$router.currentRoute.name === "RoadResourcesManager") {
      //古道
      // this.moduleTitle = '古道'
      this.queryParam.c0303 = "1";
    }
    //获取任务范围
    this.$http.post(getPermissionParams, {}).then((res) => {
      const data = res.result;
      this.taskAreaTree = data.orgTreeData;
    });
    //数据字典初始化
    this.$http
      .post(getBatchDict, {
        dictFields: "B0106,C0105,B0113,B0114,B0117,B0118,B0202",
      })
      .then((res) => {
        this.dictData = res.result;
        Object.keys(this.dictData).forEach((key) => {
          this.dictData[key].forEach((e) => {
            e.label = e.dictValue;
            e.value = e.dictKey;
          });
        });
        this.b0117DictData = this.dictData.B0117;
        this.b0118DictData = this.dictData.B0118;
        // 修改筛选列表
        const xTable = this.$refs.xTable;
        xTable.setFilter("b0106Name", this.dictData.B0106);
        xTable.setFilter("b0117Name", this.b0117DictData);
      });
    this.$http
        .post(getDictCondition, {
          dictField: "B0104",
          classify: '4',
        })
        .then((res) => {
          const b0104 = res.result;
          b0104.forEach((e) => {
            e.label = e.dictValue;
            e.value = e.dictKey;
          });
          this.$set(this.dictData, "B0104", b0104);
          const xTable = this.$refs.xTable;
          xTable.setFilter("b0104Name", this.dictData.B0104);
        });
    this.$http
      .post(getDictCondition, {
        dictField: "B0105",
        classify: '4',
      })
      .then((res) => {
        const b0105 = res.result;
        b0105.forEach((e) => {
          e.label = e.dictValue;
          e.value = e.dictKey;
        });
        this.$set(this.dictData, "B0105", b0105);
        const xTable = this.$refs.xTable;
        xTable.setFilter("b0105Name", this.dictData.B0105);
      });
    this.$http.post(getSQAndJD, {}).then((res) => {
      this.sqData = res.result.sqData;
      this.sqData.forEach((item) => {
        item.label = item.orgName;
        item.value = item.orgId;
      });
      this.jdData = res.result.jdData;
      Object.keys(this.jdData).forEach((key) => {
        this.jdData[key].forEach((e) => {
          e.label = e.orgName;
          e.value = e.orgId;
        });
      });
      const xTable = this.$refs.xTable;
      const column = xTable.getColumnByField("b0107");
      // 修改筛选列表
      xTable.setFilter(column, this.sqData);
    });
  },
  mounted() {
    this.$nextTick(() => {
      this.findGJResource();
      this.columns = this.$refs.xTable.getColumns();
    });
    this.$nextTick(() => {
      this.getTableHeight();
    });
    window.addEventListener("resize", this.getTableHeight);
  },
  methods: {
    goPage(){
      window.location.href = `https://gxl.wenzhou.gov.cn:8848/#/historical?user_id=${this.userInfo.userId}`
    },
    allotPersonBatch(){
      if (
          this.queryParam.manageAreas == null ||
          this.queryParam.manageAreas.length === 0
      ) {
        modal.warn({
          title: "提示",
          content: "请先选择管理区域并勾选(全选)点位后再批量分配人员",
        });
        return;
      }
      if (this.checkRecords.length === 0) {
        modal.warn({ title: "提示", content: "请先选择点位，再分配维护人员" });
        return;
      }

      this.formVisible = true
      this.$nextTick(()=>{
        this.$refs.maintPersonForm.initData(this.queryParam.manageAreas);
      })
    },
    manageAreaChange() {
      this.findGJResource();

      setTimeout(()=>{
        if(this.queryParam.manageAreas.length === 0) {
          this.desc = ''
        }else {
          this.$http.post(getResourceAllocationtheInfo, {manageAreas: this.queryParam.manageAreas}).then((res) => {
            this.desc = res.result;
          });
        }
      },300)
    },
    // 查询古迹资源信息
    findGJResource() {
      if (JSON.stringify(this.selectRuleBuild) === "{}") {
        this.selectRuleBuild = JSON.parse(JSON.stringify(this.selectRule));
      }
      const filterVOList = [];
      Object.keys(this.queryParam).forEach((key) => {
        const fieldRule = this.selectRuleBuild[key];
        if (fieldRule) {
          if (fieldRule.multiple) {
            fieldRule.values = this.queryParam[key];
          } else {
            fieldRule.data = this.queryParam[key];
          }
        }
      });
      Object.keys(this.selectRuleBuild).forEach((key) => {
        if (this.selectRuleBuild[key].data) {
          filterVOList.push({
            property: this.selectRuleBuild[key].targetField,
            data: this.selectRuleBuild[key].data,
            fuzzyQuery: this.selectRuleBuild[key].fuzzyQuery,
          });
        } else if (this.selectRuleBuild[key].values.length > 0) {
          filterVOList.push({
            property: this.selectRuleBuild[key].targetField,
            values: this.selectRuleBuild[key].values,
          });
        }
      });
      const orderVOList = [];
      Object.keys(this.orderRuleBuild).forEach((key) => {
        if (this.orderRuleBuild[key].order) {
          orderVOList.push({
            property: this.orderRuleBuild[key].targetField,
            order: this.orderRuleBuild[key].order,
          });
        }
      });
      this.queryParam.filterVOList = filterVOList;
      this.queryParam.orderVOList = orderVOList;
      this.queryParam.pageNum = this.pageInfo.currentPage;
      this.queryParam.pageSize = this.pageInfo.pageSize;
      if(this.materialFormInfo.b0202 || this.materialFormInfo.b0203){
        this.queryParam.materialFormInfo = this.materialFormInfo
      }else {
        this.queryParam.materialFormInfo = undefined
      }
      //获取古道数据
      this.queryParam.type='2'
      this.loading = true;
      this.$http
        .post(getResourceObjectList, this.queryParam)
        .then((res) => {
          this.loading = false;
          const data = res.result;
          this.tableData = data.list;
          this.pageInfo.currentPage = data.pageNum;
          this.pageInfo.pageSize = data.pageSize;
          this.pageInfo.total = data.total;
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    columnChange() {
      this.$refs.xTable.refreshColumn();
    },
    //筛选
    filterChange({ column, property, values, datas, filterList, $event }) {
      console.log(column);
      console.log(property);
      console.log(values);
      console.log(datas);
      console.log(filterList);
      console.log($event);
      //更改街道筛选字段
      if (property === "b0107") {
        this.jdDataBuild = this.jdData[values[0]];
        const xTable = this.$refs.xTable;
        const column = xTable.getColumnByField("b0108");
        // 修改筛选列表，并默认设置为选中状态
        xTable.setFilter(column, this.jdDataBuild);
      }
      if (property === "b0117Name") {
        this.b0118DictDataBuild = [];
        this.b0118DictData.forEach((item) => {
          if (item.parentKey == values[0]) {
            this.b0118DictDataBuild.push(item);
          }
        });
        const xTable = this.$refs.xTable;
        // 修改筛选列表，并默认设置为选中状态
        xTable.setFilter("b0118Name", this.b0118DictDataBuild);
      }
      //构建多字段筛选参数
      this.selectRuleBuild = JSON.parse(JSON.stringify(this.selectRule));
      console.log(this.selectRuleBuild);
      filterList.forEach((item) => {
        const fieldRule = this.selectRuleBuild[item.field];
        if (fieldRule) {
          if (fieldRule.multiple) {
            fieldRule.values = item.values;
          }else {
            fieldRule.data = item.datas[0];
          }
        }
      });

      this.findGJResource();
    },
    //排序
    sortChange({ column, property, order, sortBy, sortList, $event }) {
      console.log(column);
      console.log(property);
      console.log(order);
      console.log(sortBy);
      console.log(sortList);
      console.log($event);
      this.orderRuleBuild = JSON.parse(JSON.stringify(this.orderRule));
      sortList.forEach((item) => {
        if (this.orderRuleBuild[item.field]) {
          this.orderRuleBuild[item.field].order = item.order;
        }
      });
      this.findGJResource();
    },
    //表单处理
    handleForm() {
      if (this.modalTitle === "查看") {
        this.visible = false;
        return;
      }
      this.$refs.pointInfo.saveOrUpdate().then((formData) => {
        console.log(formData);
        if(formData.b0132 && formData.b0132.length > 0){
          let b0132 = ''
          for (let i = 0; i < formData.b0132.length; i++) {
            if(i === formData.b0132.length - 1){
              b0132 = b0132 + formData.b0132[i]
            }else {
              b0132 = b0132 + formData.b0132[i] + ","
            }
          }
          formData.b0132 = b0132
        }else {
          formData.b0132 = undefined
        }
        formData.c0303 = this.queryParam.c0303;
        formData.b0110 = formData.b0111 + "," + formData.b0112;
        if (formData.b0101) {
          //编辑
          this.$http.post(updateResource, formData).then((res) => {
            modal.info({ title: "成功提示", content: "编辑成功" ,maskClosable: true});
            this.visible = false;
            this.findGJResource();
          });
        } else {
          //新增
          this.$http.post(saveResource, formData).then((res) => {
            modal.info({ title: "成功提示", content: "新增成功" ,maskClosable: true});
            this.visible = false;
            this.findGJResource();
          });
        }
      });
    },
    // 搜索
    onSearch() {
      this.findGJResource();
    },
    // 刷新
    refresh() {
      this.$refs.xTable.clearFilter();
      this.selectRuleBuild = JSON.parse(JSON.stringify(this.selectRule));
      this.queryParam.b0102 = null;
      this.findGJResource();
    },
    // 字段展示- 筛选确认
    fieldConfirm() {
      this.fieldVisible = false;
      this.$refs.xTable.refreshColumn();
    },
    // 字段展示-还原
    fieldRevert() {
      this.fieldVisible = false;
      this.columns.forEach((el) => {
        el.visible = true;
      });
      this.$refs.xTable.refreshColumn();
    },
    // 新增
    openAdd() {
      this.flag = 'save'
      this.modalTitle = "新增";
      this.visible = true;
      this.objectInfo.b0101 = null;
      this.saveFlag = false;
    },
    // 导出
    exportFile() {
      commonExcelExport('resourcesManager',this.queryParam);
    },
    // 选择框
    selectChangeEvent() {
      this.checkRecords = this.$refs.xTable.getCheckboxRecords();
      this.count = this.checkRecords.length
    },
    // 选择框-all
    selectAllEvent() {
      this.checkRecords = this.$refs.xTable.getCheckboxRecords();
      this.count = this.checkRecords.length
    },
    // 操作
    operate(row, type) {
      console.log(row);
      if (type === "query") {
        this.modalTitle = "查看";
        this.okButtonDisabled = true;
        this.visible = true;
        this.objectInfo.b0101 = row.b0101;
        this.saveFlag = true;
        this.flag = 'query'
      } else if (type === "edit") {
        this.flag = 'edit'
        this.modalTitle = "编辑";
        this.visible = true;
        this.objectInfo.b0101 = row.b0101;
        this.saveFlag = false;
      }
    },
    // 分页
    handlePageChange({ currentPage, pageSize }) {
      this.pageInfo.currentPage = currentPage;
      this.pageInfo.pageSize = pageSize;
      this.findGJResource();
    },
    // 表格高度
    getTableHeight() {
      this.$nextTick(() => {
        this.tableHeight = window.innerHeight - 371;
      });
    },
    handleOk(){
      if(this.row){
        let b0101List = [];
        b0101List.push(this.row.b0101)
        this.$refs.maintPersonForm.allotMaintPersonBatch(b0101List);
      }else {
        let b0101List = [];
        b0101List = this.checkRecords.map(item =>{
          return item.b0101
        })
        if (b0101List.length > 0) {
          this.$refs.maintPersonForm.allotMaintPersonBatch(b0101List);
        } else {
          this.$message.warning("无可保存数据!");
        }
      }
    },
    handleCancel(){
      this.formVisible = false
      this.row = null
    },
    allotOnePerson(row){
      this.row = row
      this.formVisible = true
      this.$nextTick(()=>{
        this.$refs.maintPersonForm.initData(['330300000000']);
      })
    },
    openMaterialModal(){
      this.materialVisible = true
    },
    selectByMaterial(){
      this.findGJResource()
      this.materialVisible = false
    }
  },
  beforeRouteLeave(to, from, next) {
    window.removeEventListener("resize", this.getTableHeight);
    next();
  },
};
</script>
<style lang="less" scoped>
.permission {
  //padding: 15px 20px 0;
  height: 100%;
  .desc,
  .condition {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #fff;
    > div {
      flex: 0 0 auto;
      display: flex;
      align-items: center;
    }
    .field {
      flex: 0 0 atuo;
      position: relative;
      margin-left: 15px;
      .field-box {
        position: absolute;
        top: 40px;
        left: 0;
        right: -40px;
        z-index: 99;
        border: 1px solid #2175a9;
        background: #002a44;
        border-radius: 5px;
        ul {
          padding: 10px;
          li {
            padding: 1px 0;
          }
        }
        .btn {
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 5px;
          border-top: 1px solid #2175a9;
          color: #fff;
          p {
            flex: 1;
            text-align: center;
            cursor: pointer;
            &:hover {
              color: #49bbeb;
            }
          }
        }
      }
    }
  }
  .desc {
    margin-bottom: 20px;
  }
  .condition {
    margin-bottom: 15px;
  }
  ::v-deep .vxe-checkbox--label {
    padding-left: 12px;
    color: #fff;
  }
  ::v-deep .vxe-checkbox--icon {
    box-shadow: none !important;
  }
  ::v-deep .vxe-table--filter-wrapper {
    .vxe-checkbox--label {
      color: #333;
    }
    .is--checked {
      .vxe-checkbox--label {
        color: #2466d0;
      }
    }
  }
}
</style>

